using System.Collections;
using Holoville.HOTween;
using Holoville.HOTween.Core;
using UnityEngine;

public class MessageWindow : MonoBehaviour
{
	public static MessageWindow instance;

	public MapEntranceWindow windowChangeMap;

	public GameObject panelReconnect;

	public GameObject panelLoading;

	public GameObject hitMarks;

	public GameObject redness;

	public GameObject blockPanel;

	public UISprite noConnection;

	public UISprite mapUnavailable;

	public bool showButtonCar;

	private Coroutine _hideMapUnAvailable;

	private void Awake()
	{
		instance = this;
		panelLoading.SetActive(true);
		hitMarks.SetActive(true);
		redness.SetActive(true);
		ToggleBlockPanel(false);
		MapEntrance.OnEnterMapTrigger += OnEnterMapTriggerEventHandler;
		MapEntrance.OnExitMapTrigger += OnExitMapTriggerEventHandler;
		HOTween.Init();
	}

	private void OnDestroy()
	{
		MapEntrance.OnEnterMapTrigger -= OnEnterMapTriggerEventHandler;
		MapEntrance.OnExitMapTrigger -= OnExitMapTriggerEventHandler;
		instance = null;
	}

	public void OnEnterMapTriggerEventHandler(string nameScene)
	{
		if (!GameController.instance.playerScript.inCar && !GameController.instance.playerScript.inHelic && !GameController.instance.playerScript.isSniperModeEnabled())
		{
			AimHUD.instance.ToggleAimHUD(false);
			windowChangeMap.SetInfo(nameScene);
			showButtonCar = true;
			windowChangeMap.gameObject.SetActive(true);
			if (PvPLeaderbord.instance != null)
			{
				PvPLeaderbord.instance.SwitchListPlayers(false);
			}
		}
	}

	public void OnExitMapTriggerEventHandler()
	{
		if (!GameController.instance.playerScript.inCar && !GameController.instance.playerScript.inHelic)
		{
			AimHUD.instance.ToggleAimHUD(true);
			showButtonCar = false;
			windowChangeMap.gameObject.SetActive(false);
		}
	}

	public void ToggleBlockPanel(bool active)
	{
		blockPanel.SetActive(active);
	}

	public void ShowMessageNoConnection()
	{
		noConnection.gameObject.SetActive(true);
		noConnection.alpha = 0f;
		HOTween.To(noConnection, 0.5f, new TweenParms().Prop("alpha", 1).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			StartCoroutine(HideMessageNoConnection());
		}));
	}

	private IEnumerator HideMessageNoConnection()
	{
		yield return new WaitForSeconds(1.5f);
		HOTween.To(noConnection, 0.5f, new TweenParms().Prop("alpha", 0).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			noConnection.gameObject.SetActive(false);
		}));
	}

	public void ShowMapUnAvailable()
	{
		mapUnavailable.gameObject.SetActive(true);
		mapUnavailable.alpha = 0f;
		HOTween.To(mapUnavailable, 0.5f, new TweenParms().Prop("alpha", 1).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			if (_hideMapUnAvailable != null)
			{
				StopCoroutine(_hideMapUnAvailable);
			}
			_hideMapUnAvailable = StartCoroutine(HideMapUnAvailable());
		}));
	}

	private IEnumerator HideMapUnAvailable()
	{
		yield return new WaitForSeconds(1.5f);
		HOTween.To(mapUnavailable, 0.5f, new TweenParms().Prop("alpha", 0).OnComplete((TweenDelegate.TweenCallback)delegate
		{
			mapUnavailable.gameObject.SetActive(false);
			_hideMapUnAvailable = null;
		}));
	}

	private void OnEnable()
	{
	}

	private void OnDisable()
	{
	}

	public void showPanelReconnect()
	{
		WindowManager.instance.HideAllWindow();
		panelReconnect.gameObject.SetActive(true);
		ActivityIndicator.activEnabled = true;
	}

	public void hidePanelReconnect()
	{
		panelReconnect.gameObject.SetActive(false);
		ActivityIndicator.activEnabled = false;
	}

	public void SetVisiblePanelLoading(bool val, string scene = "")
	{
		if (val)
		{
			GameController.instance.hideAllPanels();
		}
		if (val)
		{
			if (scene.Equals(string.Empty))
			{
				string text = BCWStorage.Get<string>(settings.keyForShowLoadingSprite);
				panelLoading.GetComponent<SceneLoadBar>().SetBackgroundTextureForLobby();
			}
			else if (!scene.Equals("zatichka"))
			{
				panelLoading.GetComponent<SceneLoadBar>().SetBackgroundTextureForLobby();
			}
		}
		panelLoading.gameObject.SetActive(val);
	}
}
